﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using VideoClassLibrary.Model;
using VideoClassLibrary.BusinessLogicLayer;
using System.Security.Cryptography;
public partial class UserManagement_UpdateUser : AdminUserBase
{
    protected void Page_Load(object sender, EventArgs e)
    {

        if (!IsPostBack)
        {
            UserModule um = new UserModule();
            int UID = Convert.ToInt32(Request.QueryString["UID"].ToString());
            V_user user = new V_user();
            user = um.GetUserModelById(UID);
            txtVU_email.Text = user.VU_email;
            txtVU_loginname.Text = user.VU_loginname;
            txtVU_mobile.Text = user.VU_mobile;
            chkIsEnable.Checked = user.IsAvailable == true ? true : false;
            
            //chkIsBuy.Checked = user.IsBuyingAccount==1?true:false;
            //txtVU_Password.Text="";
            txtVU_realname.Text = user.VU_realname;
            TeacherModule ta = new TeacherModule();
            List<V_School> vs = new List<V_School>();
            vs = ta.GetSchool();
            dlschool.DataSource = vs;
            dlschool.DataBind();

            if (this.CurrentUser.SchoolID == 0)
            {
            }
            else
            {
                dlschool.SelectedValue = this.CurrentUser.SchoolID.ToString();
                dlschool.Enabled = false;
            }
        }
    }
    protected void btnUpdate_Click(object sender, EventArgs e)
    {
        V_user user = new V_user();
        UserModule um = new UserModule();
        user.ID =Convert.ToInt32( Request.QueryString["UID"].ToString());
        user.SchoolID = Convert.ToInt32(dlschool.SelectedValue.ToString());
        user.update_time =DateTime.Now;
        user.VU_email = txtVU_email.Text.Trim();
        user.VU_loginname = txtVU_loginname.Text.Trim();
        user.VU_mobile = txtVU_mobile.Text.Trim();
        user.VU_Password = txtVU_Password.Text.Trim();
        user.VU_realname = txtVU_realname.Text.Trim();
        try
        {
            int i = um.UpdateUser(user);
            if (i > 0)
            {
                
                PageHelper.AlterMsgAndRedirect("修改学生信息成功！", "ViewUserInfoList.aspx");

            }
            else { lblMess.Text = "修改学生信息失败"; }
        }
        catch (Exception ex)
        {
            lblMess.Text = "修改学生信息失败，稍后再试！";

        }
    }
    
}
